<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>

<script>
    let str = 'num1,num2,num3,num4';

    /* ^：行开头，[]中表示取反 */
    console.log(str.match(/^num\d/g));//['num1']

    /* $：行结尾 */
    console.log(str.match(/num\d$/g));//['num4']

    /* \b：单词边界 */
    console.log(str.match(/num\d\b/g));//['num1', 'num2', 'num3', 'num4']

    /* \B：非单词边界 */
    console.log(str.match(/^num\d\B/g));//null
</script>
</html>